package bingjiling;

import com.unicom.office.OfficeRenderHelper;
import com.unicom.office.config.OfficeConfig;
import com.unicom.office.impl.OfficeConfigForJSONorXML;
import com.unicom.office.impl.OfficeRuntimeImpl;
import com.unicom.office.impl.XlsxEasyBuilder;
import com.unicom.office.runtime.OfficeRuntime;
import com.unicom.office.type.ListTypeItem;
import com.unicom.office.type.ObjectTypeItem;
import com.unicom.office.var.NumberVarItem;
import com.unicom.office.var.StringVarItem;
import duijiangji.Maolilv;
import duijiangji.WanFunc;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class main {
    static String templateRootPath = "test/对讲机/template/";
    static String resultRootPath = "test/对讲机/result/";
    static OfficeRuntime runtime = new OfficeRuntimeImpl();
    static OfficeConfig config = new OfficeConfigForJSONorXML(templateRootPath + "config.xml")
            .register(new WanFunc())
            .register(new Maolilv());
    static OfficeRenderHelper lsqrb = new OfficeRenderHelper(templateRootPath + "列收确认表-模板.xlsx", config, runtime).setBulider(new XlsxEasyBuilder());
    static OfficeRenderHelper qpgb = new OfficeRenderHelper(templateRootPath + "前评估表-模板.xlsx", config, runtime).setBulider(new XlsxEasyBuilder());
    static OfficeRenderHelper jsgfs = new OfficeRenderHelper(templateRootPath + "技术规范书-模板.docx", config, runtime);
    static OfficeRenderHelper psbg = new OfficeRenderHelper(templateRootPath + "评审报告-模板.xlsx", config, runtime).setBulider(new XlsxEasyBuilder());

    public static void main(String[] args) {
        // 基础准备

        // 读配置
        OfficeConfig config = new OfficeConfigForJSONorXML();
        for (int j = 0; j < 10; j++) {
            ObjectTypeItem objType = new ObjectTypeItem("iceitem");
            for (int i = 0; i < 10; i++) {
                if("string" == "string") {
                    objType.addProp("", new StringVarItem(""));
                }else if("number" == "number") {
                    objType.addProp("", new NumberVarItem(""));
                }
            }
            config.register(new ListTypeItem("ice", objType));
        }
        // 取数据，需要json转list
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("ice", new ArrayList<Map<String, String>>());
        data.put("5g", new ArrayList<Map<String, String>>());
        // 渲染
        OfficeRenderHelper mb = new OfficeRenderHelper("模板路径", config, runtime);
        mb.render(data, "保存位置");
    }

    static void p1(){
        HashMap<String, Object> map = new HashMap<String, Object>();
        String projectName = "秦皇岛市北戴河区疾病预防控制中心物联网公网对讲服务项目";

        map.put("projectName", projectName);
        map.put("companyName", "秦皇岛市北戴河区疾病预防控制中心");
        map.put("year", "2020");
        map.put("month", "5");
        map.put("num", "6");
        map.put("price", "700");
        map.put("maxCostPrice", "580");
        map.put("costPrice", "540");
        map.put("jifeiNum", "（暂无）");
        map.put("accountManager", "张春艳");
        map.put("projectLeader", "张春艳");

        renderLSQRB(projectName, map);
    }

    static void renderLSQRB(String projectName, HashMap<String, Object> data){
        String targetPath = resultRootPath + projectName;
        File file = new File(targetPath);
        if(!file.exists()){
            file.mkdirs();
        }
        lsqrb.render(data, targetPath + "/列收确认表-" + projectName + ".xlsx");
    }
}
